package org.stormphoenix.bbsfamily.controller

import java.io.Serializable
import java.sql.Timestamp
import kotlin.properties.Delegates

class CommonResult<T> : Serializable {
    var status by Delegates.notNull<Int>()

    val timestamp: Timestamp = Timestamp(System.currentTimeMillis())

    var error: String = ""

    var message: String = ""

    var path: String = ""

    var data: T? = null

    constructor(status: Int = failed, error: String = "", message: String = "", path: String = "", data: T? = null) {
        this.status = status
        this.error = error
        this.message = message
        this.path = path
        this.data = data
    }

    companion object {
        val success = DescEnum.SUCCESS.code
        val failed = 0
        fun unauth(): CommonResult<Any> =
            CommonResult(status = DescEnum.UNAUTH.code, error = DescEnum.UNAUTH.description)

        fun forbidden(): CommonResult<Any> =
            CommonResult(status = DescEnum.FORBIDDEN.code, error = DescEnum.FORBIDDEN.description)

    }
}